package com.szholly.pro.watergas_server.ps.android.service;

import java.util.ArrayList;
import java.util.List;

import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.szholly.pro.watergas_server.common.data.DataUtil;
import com.szholly.utils.util.JSONUtils;
import com.szholly.data.general.GlobalParameter;
import com.szholly.data.general.RowBase;

import net.sf.json.JSONArray;

@Service
public class SupplyWaterDetailService {
	/**
	 * android移动运营获取定期维护详情
	 * 
	 * @param task_code
	 *            任务编号
	 * @return
	 * @throws Exception
	 */

	public String getDqwhDetailData(String task_code) {
		List<GlobalParameter> parms = new ArrayList<GlobalParameter>();
		String sql = "select t.item_value ,t.item ,t1.s_domaincaption ,"
				+ " decode(t.item_value,0,'-',1,to_char(t2.start_time,'yyyy-MM-dd HH24:MI:SS'))"
				+ " as stime,decode(t.item_value,0,'-',1,to_char(t2.end_time,'yyyy-MM-dd HH24:MI:SS'))"
				+ " as etime ,decode(t.item_value,0,'-',1,to_char(t2.finish_time,'yyyy-MM-dd HH24:MI:SS'))"
				+ " as ftime from OPERATION_RECORD_MAINTAINANCE t left join"
				+ "  data_defulatdomain t1 on t.item = t1.s_domaincode left join"
				+ " operation_task t2 on t.task_code = t2.task_code  where t1.s_domainname ='供水运维项' ";
		if (!task_code.isEmpty()) {
			sql += " and t.task_code = @task_code ";
			parms.add(new GlobalParameter("task_code", task_code));
		}

		sql += "order by t.item asc";
		List<RowBase> rows = DataUtil.getSelectRows(sql, parms);
		JSONArray array = JSONArray.fromObject(rows);
		if (rows != null && rows.size() >= 0) {
			Object[] array1 = rows.toArray();
			return JSONUtils.toJSONString(rows);
		} else {
			return "";
		}
	}
	/**
	 * 获取供水数据比对详情数据
	 * 
	 * @param flow_type
	 * @param wwtp_id
	 * @return
	 */
	public String getGsSjbdDetailData(String task_code) {
		List<GlobalParameter> parms = new ArrayList<GlobalParameter>();
		String sql = "select t1.s_domaincaption,t1.s_domaincaption,t.guid,t.task_code,to_char(t.tm,'yyyy-mm-dd')as tm,"
				+ "t.measured_value,t.gbmethod_value from DATA_COMPARISON t left join "
				+ "(select t.S_DOMAINCODE,t.S_DOMAINCAPTION  from data_defulatdomain  t  "
				+ "where S_DOMAINNAME='MONITOR_PARAM') t1 on t.iterm_param = t1.S_DOMAINCODE where 1=1 ";
		if (!task_code.isEmpty()) {
			sql += " and t.task_code =@task_code";
			parms.add(new GlobalParameter("task_code", task_code));
		}
		List<RowBase> rows = DataUtil.getSelectRows(sql, parms);
		if (rows != null && rows.size() >= 0) {
			return JSONUtils.toJSONString(rows);
		} else {
			return "";
		}
	}
	/**
	 * 获取供水备件耗材更换详情数据
	 * 
	 * @param flow_type
	 * @param wwtp_id
	 * @return
	 */
	public String getSbgcghDetailData(String task_code) {
		List<GlobalParameter> parms = new ArrayList<GlobalParameter>();
		String sql = "select t1.s_domaincaption,t.guid,t.task_id,t.material_type,t.material_quantity,"
				+ "to_char(t.replace_date,'yyyy-mm-dd,hh24:mi:ss')as replace_date,t.replace_result,t.material_unit from OP_MATE_REPLACE t "
				+ "left join (select t.S_DOMAINCODE,t.S_DOMAINCAPTION  from data_defulatdomain  t  "
				+ "where S_DOMAINNAME='供水耗材名称') t1 on t.material_type = t1.s_domaincode where 1=1";
		if (!task_code.isEmpty()) {
			sql += " and t.task_id =@task_code";
			parms.add(new GlobalParameter("task_code", task_code));
		}
		List<RowBase> rows = DataUtil.getSelectRows(sql, parms);
		if (rows != null && rows.size() >= 0) {
			return JSONUtils.toJSONString(rows);
		} else {
			return "";
		}
	}
	/**
	 * 获取供水异常处理详情数据
	 * 
	 * @param flow_type
	 * @param wwtp_id
	 * @return
	 */
	public String getGsYcclDetailData(String task_code) {
		List<GlobalParameter> parms = new ArrayList<GlobalParameter>();
		String sql = "select t1.s_domaincaption,t.guid,t.status,t.exception_reason,t.process_result,t.exception_process,"
				+ "to_char(t.start_time,'yyyy-mm-dd,hh24:mi:ss')as start_time,"
				+ "to_char(t.end_time,'yyyy-mm-dd,hh24:mi:ss')as end_time,"
				+ "to_char(t.restore_time,'yyyy-mm-dd,hh24:mi:ss')as restore_time " + "from OP_ALAR_PROC t "
				+ "left join (select t.s_domaincode,t.s_domaincaption from data_defulatdomain t "
				+ "where t.s_domainname='供水异常故障项') t1 on t.exception_reason = t1.s_domaincode where 1=1";
		if (!task_code.isEmpty()) {
			sql += " and t.task_code =@task_code";
			parms.add(new GlobalParameter("task_code", task_code));
		}
		List<RowBase> rows = DataUtil.getSelectRows(sql, parms);
		if (rows != null && rows.size() >= 0) {
			return JSONUtils.toJSONString(rows);
		} else {
			return "";
		}
	}
}
